﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rep="urn:report-extended-utilities"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl rep">
  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="report-name">SharePoint Generic Report</xsl:param>
  <xsl:param name="report-chart-type">Bar</xsl:param>
  <xsl:param name="report-date" />
  <xsl:template match="/">
    <xsl:variable name="report-legend-title">Metrics</xsl:variable>
    <Report>
      <xsl:attribute name="Name">
        <xsl:value-of select="$report-name"/>
      </xsl:attribute>
      <xsl:attribute name="ChartType">
        <xsl:value-of select="$report-chart-type"/>
      </xsl:attribute>
      <xsl:attribute name="LegendTitle">
        <xsl:value-of select="$report-legend-title"/>
      </xsl:attribute>
      <Filters>
        <Filter Name="All" />
        <xsl:for-each select="//WebApplications/WebApplication">
          <Filter Name="{@Url}" FilterAttribute="WebApplication" FilterValue="{@Id}" />
        </xsl:for-each>
        <Filter Name="Metric - # site collections" FilterAttribute="Metric" FilterValue="NumberOfSites" />
        <Filter Name="Metric - # websites" FilterAttribute="Metric" FilterValue="NumberOfWebs" />
        <Filter Name="Metric - Avg webs/site cols" FilterAttribute="Metric" FilterValue="AvgWebsPerSites" />
      </Filters>
      <Series>
        <xsl:for-each select="//WebApplications/WebApplication">
          <xsl:variable name="NumSites" select="count(Sites/Site)"/>
          <xsl:variable name="NumWebs" select="count(Sites/Site/Webs/Web)"/>
          <xsl:variable name="AverageWebsPerSites" select="$NumSites div $NumWebs"/>
          <Serie>
            <xsl:attribute name="Name">
              <xsl:value-of select="@Url"/>
            </xsl:attribute>
            <Item>
              <xsl:attribute name="Name"># site collections</xsl:attribute>
              <xsl:attribute name="Value">
                <xsl:value-of select="$NumSites"/>
              </xsl:attribute>
              <xsl:attribute name="WebApplication">
                <xsl:value-of select="@Id" />
              </xsl:attribute>
              <xsl:attribute name="Metric">NumberOfSites</xsl:attribute>
              <xsl:attribute name="Date">
                <xsl:value-of select="$report-date"/>
              </xsl:attribute>
            </Item>
            <Item>
              <xsl:attribute name="Name"># websites</xsl:attribute>
              <xsl:attribute name="Value">
                <xsl:value-of select="$NumWebs"/>
              </xsl:attribute>
              <xsl:attribute name="WebApplication">
                <xsl:value-of select="@Id" />
              </xsl:attribute>
              <xsl:attribute name="Metric">NumberOfWebs</xsl:attribute>
              <xsl:attribute name="Date">
                <xsl:value-of select="$report-date"/>
              </xsl:attribute>
            </Item>
            <Item>
              <xsl:attribute name="Name">Avg webs/sites</xsl:attribute>
              <xsl:attribute name="Value">
                <xsl:value-of select="$AverageWebsPerSites"/>
              </xsl:attribute>
              <xsl:attribute name="WebApplication">
                <xsl:value-of select="@Id" />
              </xsl:attribute>
              <xsl:attribute name="Metric">AvgWebsPerSites</xsl:attribute>
              <xsl:attribute name="Date">
                <xsl:value-of select="$report-date"/>
              </xsl:attribute>
            </Item>
          </Serie>
        </xsl:for-each>
      </Series>
    </Report>
  </xsl:template>
</xsl:stylesheet>
